package homework1;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/SomeServlet")
public class SomeServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=UTF-8");
		String name = (String) request.getAttribute("uname");
		PrintWriter out = response.getWriter();
		/*
		 * if (name != null) out.print(name);
		 */
		
		// response.sendRedirect("WEB-INF/test.html");// /表示的是http://localhost:8080
		// 前面不加/ 表示在当前目录下
		// 重定向访问不到内部资源
		request.getRequestDispatcher("WEB-INF/test.html").forward(request, response);
		// /是http://localhost:8080/WebProject
		// 转发不能访问外部资源
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
